<?php

require "entity/Bean.class.php";

class Users extends Bean
{		
	protected $id;
	protected $user_name;
	protected $user_avatar;
	protected $password;
	protected $email;
	protected $first_name;
	protected $last_name;
	protected $birthday;
	protected $register_date;
	protected $register_ip;
	protected $visited_date;
	protected $visited_ip;
	protected $active_code;
	protected $status;
	protected $sign;
	protected $group_id;
	protected $login_count;

	public function getUsername() {
		return "User:". $this->user_name;
	}
}



/* 
#################################################

public class UserBean {

    protected String username, email, location;

    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }

    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }

    public String getLocation {
        return location;
    }
    public void setLocation(String location) {
        this.location = location;
    }
}

#################################################

abstract class Bean {
    public function __call($name, $arguments) {
        if (strpos($name, 'get') === 0) {
            $property = strtolower(substr($name,3,1)) . substr($name,4);
            return $this->$property;
        }
        elseif (strpos($name, 'set') === 0) {
            $property = strtolower(substr($name,3,1)) . substr($name,4);
            return $this->$property = $arguments[0];
        }
        else {
            throw new Exception("Method $name does not exist");
        }
    }

    public function __get($name) {
        $getter = 'get' . ucfirst($name);
        if (method_exists($this, $getter)) {
            return call_user_func(array($this, $getter));
        }
        return $this->$name;
    }

    public function __set($name, $value) {
        $setter = 'set' . ucfirst($name);
        if (method_exists($this, $setter)) {
            call_user_func(array($this, $setter), $value);
        }
        else {
            $this->$name = $value;
        }
    }
}

#################################################

#class 1

class UserBean extends Bean {
    protected $username, $email, location;
}


$user = new UserBean();
$user->setUsername('Jim');
echo $user->getUsername();

#################################################

#class 2

class UserBean extends Bean {
    protected $username, $email, location;
    public function getUsername() {
        return "User: $username";
    }
}

$user = new UserBean();
$user->username = 'Jim';
echo $user->username;;
  
*/